<template>
    <div>
        <!-- 顶部滑动条 -->
        <div id="slider" class="mui-slider">
            <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id === 0 ?'mui-active':'']" 
                    v-for="item in cates" :key="item.id" @tap="getImgs(item.id)">
                        {{ item.title }}
                    </a>
                </div>
            </div>
        </div>

        <!-- 图片列表区域 -->
        <ul class="photo_list">
            <router-link :to="'/home/photoinfo/' + item.id" tag="li" 
            v-for="item in list" :key="item.id">
                <img v-lazy="item.img_url">
                <div class="info">
                    <div class="info_title">{{item.title}}</div>
                    <div class="info_body">{{item.zhaiyao}}</div>
                </div>
            </router-link>
        </ul>
    </div>
</template>

<script>

import mui from '../../lib/mui/js/mui.min.js'

export default {
    data() {
        return {
            cates: [],
            list: []
        }
    },
    mounted() {
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
        })
    },
    created() {
        this.getAllCategory()
        this.getImgs(0)
    },
    methods: {
        getAllCategory() {
            this.$http.get('api/getimgcategory').then(res => {
                if(res.body.status === 0) {
                    res.body.message.unshift({title: "全部", id: 0})
                    this.cates = res.body.message
                }
            }, res => {
                this.cates = [
                    {title: "全部", id: 0},
                    {title: "家居生活", id: 1},
                    {title: "摄影设计", id: 2},
                    {title: "科技生活", id: 3},
                    {title: "美女写真", id: 4},
                    {title: "自然美景", id: 5},
                    {title: "卡通动漫", id: 6}
                ]
            })
        },
        getImgs(cateid) {
            this.$http.get('api/getimages/' + cateid).then(res => {
                if(res.body.status === 0) {
                    this.list = res.body.message
                }
            }, res => {
                var _this = this
                if(cateid === 1) {
                    _this.list = [
                        {
                            title: "家居生活", 
                            id: 50,
                            img_url:'/src/images/l7.jpg',
                            zhaiyao: '家居生活'
                        },
                        {
                            title: "家居生活", 
                            id: 51,
                            img_url:'/src/images/l7.jpg',
                            zhaiyao: '家居生活'
                        },
                        {
                            title: "家居生活", 
                            id: 52,
                            img_url:'/src/images/l7.jpg',
                            zhaiyao: '家居生活'
                        },
                        {
                            title: "家居生活", 
                            id: 53,
                            img_url:'/src/images/l7.jpg',
                            zhaiyao: '家居生活'
                        },
                        {
                            title: "家居生活", 
                            id: 54,
                            img_url:'/src/images/l7.jpg',
                            zhaiyao: '家居生活'
                        },
                        {
                            title: "家居生活", 
                            id: 55,
                            img_url:'/src/images/l7.jpg', 
                            zhaiyao: '家居生活'
                        }
                    ]
                }else{
                    _this.list = [
                        {
                            title: "全部", 
                            id: 50,
                            img_url:'/src/images/author.jpg',
                            zhaiyao: '全部'
                        },
                        {
                            title: "全部", 
                            id: 51,
                            img_url:'/src/images/author.jpg',
                            zhaiyao: '全部'
                        },
                        {
                            title: "全部", 
                            id: 52,
                            img_url:'/src/images/author.jpg',
                            zhaiyao: '全部'
                        },
                        {
                            title: "全部", 
                            id: 53,
                            img_url:'/src/images/author.jpg',
                            zhaiyao: '全部'
                        },
                        {
                            title: "全部", 
                            id: 54,
                            img_url:'/src/images/author.jpg',
                            zhaiyao: '全部'
                        },
                        {
                            title: "全部", 
                            id: 55,
                            img_url:'/src/images/author.jpg', 
                            zhaiyao: '全部'
                        }
                    ]
                }
                
            })
        }
    }
}
</script>

<style lang="scss" scoped>
    *{
        touch-action: pan-y;
    }
    .photo_list{
        list-style: none;
        margin: 0;
        padding: 0 10px;
        li{
            text-align: center;
            background-color: #ccc;
            margin-bottom: 10px;
            box-shadow: 0 0 10px #999;
            position: relative;

            img[lazy=loading] {
                width: 40px;
                height: 300px;
                margin: auto;
            }
            img{
                width: 100%;
                vertical-align: middle;
            }

            .info{
                width: 100%;
                max-height: 140px;
                color: #fff;
                text-align: left;
                position: absolute;
                background-color: rgba(0,0,0,0.4);
                bottom: 0;
                .info_title{
                    font-size: 14px;
                }
                .info_body{
                    font-size: 12px;
                }
            }
        }
    }
    
</style>
